define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wx/wxsms/index',
                    add_url: 'wx/wxsms/add',
                    edit_url: 'wx/wxsms/edit',
                    del_url: 'wx/wxsms/del',
                    multi_url: 'wx/wxsms/multi',
                    table: 'wxsms',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_sn', title: __('Order_sn')},
                        {field: 'content', title: __('Content')},
                        {field: 'send', title: __('Send'), searchList: {"0":__('需发送'),"1":__('Send 1'),"2":__('Send 2')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
              queryParams: function (params) {
                //这里可以追加搜索条件
                var filter = JSON.parse(params.filter);
                var op = JSON.parse(params.op);
                //这里可以动态赋值，比如从URL中获取admin_id的值，filter.admin_id=Fast.api.query('admin_id');
                filter.order_sn = order_sn;
                op.order_sn = "=";
                params.filter = JSON.stringify(filter);
                params.op = JSON.stringify(op);
                return params;
              }
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});